package com.blockmeta.bbs.minemodule.adapter;

import android.content.Context;


import com.blockmeta.bbs.baselibrary.utils.FormatUtil;
import com.blockmeta.bbs.businesslibrary.adapter.expandablelist.BaseViewHolder;
import com.blockmeta.bbs.businesslibrary.adapter.expandablelist.GroupedRecyclerViewAdapter;
import com.blockmeta.bbs.minemodule.R;
import com.blockmeta.bbs.minemodule.pojo.CoinGotDetailPOJO;

import java.util.ArrayList;
import java.util.List;

/**
 * @author AirThor
 * @date 2018/10/16.
 * 任务中心列表适配器
 */
public class CoinGotDetailAdapter extends GroupedRecyclerViewAdapter {
    private ArrayList<CoinGotDetailPOJO> mGroups;
    private Context mContext;

    public CoinGotDetailAdapter(Context context, ArrayList<CoinGotDetailPOJO> groups) {
        super(context);
        mGroups = groups;
        mContext = context;
    }

    @Override
    public int getGroupCount() {
        return mGroups == null ? 0 : mGroups.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        List<CoinGotDetailPOJO.ListBean> children = mGroups.get(groupPosition).list;
        return children == null ? 0 : children.size();
    }

    @Override
    public boolean hasHeader(int groupPosition) {
        return true;
    }

    @Override
    public boolean hasFooter(int groupPosition) {
        return false;
    }

    @Override
    public int getHeaderLayout(int viewType) {
        return R.layout.item_group_title;
    }

    @Override
    public int getFooterLayout(int viewType) {
        return 0;
    }

    @Override
    public int getChildLayout(int viewType) {
        return R.layout.item_coin_got;
    }

    @Override
    public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) {
        CoinGotDetailPOJO tasksBean = mGroups.get(groupPosition);
        holder.setText(R.id.tv_group_title,tasksBean.title);
    }

    @Override

    public void onBindFooterViewHolder(BaseViewHolder holder, int groupPosition) {

    }

    @Override
    public void onBindChildViewHolder(BaseViewHolder holder, int groupPosition, int childPosition) {
        final CoinGotDetailPOJO.ListBean listBean = mGroups.get(groupPosition).list.get(childPosition);
        holder.setText(R.id.tv_task_name,listBean.content);
        String coins = listBean.award>0?"+"+listBean.award:listBean.award+"";
        holder.setText(R.id.tv_got_num,coins);
        String time = FormatUtil.getTimetoHMS(listBean.time,"MM-dd HH:mm:ss");
        holder.setText(R.id.tv_time,time);
    }
}
